<?php 
class Contactgegevens extends CI_Controller {
	
	public function __construct()
	{
		parent::__construct();
		$this->load->helper('form');
		$this->load->helper('url');
		$this->load->library('form_validation');
	}
	
	public function index(){
		$this->showContactgegevens();
	}	
	
	public function addContactgegevens(){
		if($this->validationRules()) {
			if ($this->form_validation->run() == FALSE){
				$this->showContactgegevens();
			}
			else {
				$this->load->model('contactgegevens_model');
				$this->contactgegevens_model->addContactgegevens();
				$this->showContactgegevens();
			}
		}
	}
	
	public function updateContactgegevens(){
		$this->load->model('contactgegevens_model');
		$this->contactgegevens_model->updateContactgegevens($this->uri->segment(4));
		$this->showContactgegevens();
	}
	
	public function editContactgegevens(){
		$this->load->model('contactgegevens_model');
		$data['query'] = $this->contactgegevens_model->getContactgegevens($this->uri->segment(4));
		$this->load->view('contactgegevens_view', $data);
	}
	
	public function showContactgegevens(){
		$this->load->model('contactgegevens_model');
		$data['query'] = $this->contactgegevens_model->getContactgegevens(1);
		$this->load->view('contactgegevens_view', $data);
	}
	
	public function verwijderContactgegevens(){
		$contactgegevensid = $this->uri->segment(4);
		$this->load->model('contactgegevens_model');
		$this->contactgegevens_model->deleteContactgegevens($contactgegevensid);
		$this->showContactgegevens();	
	}
	
	private function validationRules(){
		$this->form_validation->set_rules('email', 'E mail adres', 'required');
		$this->form_validation->set_rules('vaste_telefoon_nr', 'vaste telefoon nummer', 'required');
		$this->form_validation->set_rules('mobiel_telefoon_nr', 'mobiel telefoon nummer', 'required');
		return true;
	}
}
?>